﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using MarginTrading.Entity;
using MarginTrading.Services;
using Microsoft.Reporting.WebForms;
using MarginTrading.Common;

namespace MarginTrading.site
{
    public partial class PortfolioReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["Username"] == null)
            //{
            //    Response.Redirect("Login.aspx");
            //}
            //LoadReport(Session["UserName"].ToString());
            LoadReport("DSA-623232310-VN-00");
        }

        private void LoadReport(string clientId)
        {
            try
            {
                Client client = ClientService.GetClientByCode(clientId);

                if (client == null)
                {
                    client = ClientService.GetClientByCode(clientId.ToUpper());
                    if (client == null)
                    {
                        client = new Client();
                    }
                    else
                    {
                        clientId = clientId.ToUpper();
                    }
                }

                ReportDataSource ds = new ReportDataSource();
                ds.Name = "master";
                ds.Value = ReportServices.GetPortfolioValuation1(clientId);


                ReportViewer1.LocalReport.ReportPath = "PortfolioValuation1.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(ds);

                Config AgentCodeConfig = ConfigServices.GetConfigByName("Agent Code");
                string AgentCode = "cts";
                if (AgentCodeConfig != null)
                {
                    AgentCode = AgentCodeConfig.Value;
                }

                //TODO:Remove this 
                AgentCode = Reports.AGENT_CODE;

                ReportViewer1.LocalReport.SetParameters(new ReportParameter[] {
                        new ReportParameter("ImageLink",AgentCode.ToLower()),
                        new ReportParameter("CompanyName",Reports.COMPANY_NAME),
                        new ReportParameter("ClientID",client.Code),
                        new ReportParameter("Name",string.Concat(client.Initials," ", client.Surname) ),
                        new ReportParameter("Address",string.Concat(client.Address_1," ",client.Address_2," ",client.Address_3," ",client.Address_4)),
                        new ReportParameter("AdvisorID",client.Advisor)});

                //this.reportViewer1.RefreshReport();
                //reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
                //reportViewer1.ZoomMode = ZoomMode.Percent;
                //reportViewer1.ZoomPercent = 100;
            }
            catch (Exception e)
            {

            }
        }



    }
}
